package com.choosefine.it.team.controller;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.team.model.PersonalCenter;
import com.choosefine.it.team.model.vo.PersonInfoDetailVO;
import com.choosefine.it.team.service.ItemInfoService;
import com.choosefine.it.team.service.TeamHomePageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/team")
@Api(value = "班组个人主页", description = "毛俊")
public class TeamHomePageController extends BaseController {
	@Autowired
	private TeamHomePageService teamHomePageService;
	
	@Autowired
	private ItemInfoService itemInfoService;

	@ApiOperation(value = "获取班组用户的个人主页详情", notes = "根据userCode获取获取班组用户的个人主页详情",response=PersonInfoDetailVO.class)
	@ApiImplicitParam(name = "userCode", value = "用户的标识符", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "/TeamHomePageDetail/{userCode}", method = RequestMethod.GET)
	public String getTeamHomePageDetail(@PathVariable String userCode) {
		String result = null;
		PersonInfoDetailVO p = teamHomePageService.getPersonDetailInfoByUserCode(userCode);
			if (p != null) {
				List<String> tlist = itemInfoService.selectTeamAffiliatedUnitsByUserCode(userCode);
				p.setAffiliatedunit(tlist);
				result = responseSuccess(p,ResultCode.SUCCESS,ResultCode.MSG_QUERY_SUCCESS);
			} else {
				result=responseFail(ResultCode.FAILED,ResultCode.MSG_DATA_ISEMPTY);
			}
		return result;
	}

	//废弃
	@Deprecated
    @ApiIgnore
	@ApiOperation(value = "获取班组用户的个人主页", notes = "根据userCode获取获取班组用户的个人主页")
	@ApiImplicitParam(name = "userCode", value = "用户的标识符", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "/TeamHomePage/{userCode}", method = RequestMethod.GET)
	public String getTeamHomePage(@PathVariable String userCode) {
		String result = null;
			PersonalCenter p = teamHomePageService.getPersonalCenter(userCode);
			if (p != null) {
				result = responseSuccess(p,ResultCode.SUCCESS,ResultCode.MSG_QUERY_SUCCESS);
				
			} else {
				result = responseFail(ResultCode.FAILED,ResultCode.MSG_DATA_ISEMPTY);
			}
		return result;
	}
}
